package com.ruoyi.sys.security.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.sys.security.domain.TbIncident;
import com.ruoyi.sys.security.service.ITbIncidentService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 园区事件记录Controller
 *
 * @author iuxin
 * @date 2022-05-25
 */
@Api(value = "园区事件记录", tags = "园区事件记录操作接口")
@RestController
@RequestMapping("/incidentLog/incident")
public class TbIncidentController extends BaseController
{
    @Autowired
    private ITbIncidentService tbIncidentService;

    /**
     * 查询园区事件记录列表
     */
    @ApiOperation(value = "查询园区事件记录列表",notes = "查询园区事件记录列表")
    @PreAuthorize("@ss.hasPermi('incidentLog:incident:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbIncident tbIncident)
    {
        startPage();
        List<TbIncident> list = tbIncidentService.selectTbIncidentList(tbIncident);
        return getDataTable(list);
    }

    /**
     * 导出园区事件记录列表
     */
    @PreAuthorize("@ss.hasPermi('incidentLog:incident:export')")
    @Log(title = "园区事件记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbIncident tbIncident)
    {
        List<TbIncident> list = tbIncidentService.selectTbIncidentList(tbIncident);
        ExcelUtil<TbIncident> util = new ExcelUtil<TbIncident>(TbIncident.class);
        util.exportExcel(response, list, "园区事件记录数据");
    }

    /**
     * 获取园区事件记录详细信息
     */
    @ApiOperation(value = "获取园区事件记录详细信息",notes = "获取园区事件记录详细信息")
    @PreAuthorize("@ss.hasPermi('incidentLog:incident:query')")
    @GetMapping(value = "/{iId}")
    public AjaxResult getInfo(@PathVariable("iId") Long iId)
    {
        return AjaxResult.success(tbIncidentService.selectTbIncidentByIId(iId));
    }

    /**
     * 新增园区事件记录
     */
    @PreAuthorize("@ss.hasPermi('incidentLog:incident:add')")
    @Log(title = "园区事件记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbIncident tbIncident)
    {
        return toAjax(tbIncidentService.insertTbIncident(tbIncident));
    }

    /**
     * 修改园区事件记录
     */
    @PreAuthorize("@ss.hasPermi('incidentLog:incident:edit')")
    @Log(title = "园区事件记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbIncident tbIncident)
    {
        return toAjax(tbIncidentService.updateTbIncident(tbIncident));
    }

    /**
     * 删除园区事件记录
     */
    @PreAuthorize("@ss.hasPermi('incidentLog:incident:remove')")
    @Log(title = "园区事件记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{iIds}")
    public AjaxResult remove(@PathVariable Long[] iIds)
    {
        return toAjax(tbIncidentService.deleteTbIncidentByIIds(iIds));
    }
}
